package com.my.model;

import java.util.HashMap;

/**
 * @author WangLuoXin
 * &#064;Date 2024/10/29  16:47
 * 前端参数接收容器
 **/
public class RequestMap extends HashMap<String, Object> {

    public <T> T get(String key, Class<T> c) {
        Object value = get(key);
        if (null != value) {
            try {
                return c.cast(value);
            } catch (Exception e) {
                throw new ClassCastException(key + " 不属于 " + c.getName() + " 类型");
            }
        }
        return null;
    }

    public String getStr(String key) {
        Object value = get(key);
        if (value instanceof String) {
            return (String) value;
        }
        if (null == value) {
            return null;
        }
        throw new ClassCastException(key + " 不属于 " + String.class.getName() + " 类型");
    }

}
